<script setup lang="ts">
import { getHomeGoodsGuessLikeAPI } from '@/services/home'
import type { PageParams } from '@/types/global'
import type { GuessItem } from '@/types/home'
import { onMounted,ref } from 'vue'
import { useI18n } from 'vue-i18n'
const { t,locale } = useI18n()
// 分页参数
const pageParams: Required<PageParams> = {
	page: 1,
	pageSize: 10,
}
// 猜你喜欢的列表
const guessList = ref<GuessItem[]>([])
// 已结束标记
const finish = ref(false)
// 获取猜你喜欢数据
const getHomeGoodsGuessLikeData = async () => {
	// 退出分页判断
	if (finish.value === true) {
		return uni.showToast({ icon: 'none',title: t('no.more.data') + '~' })
	}
	const res = await getHomeGoodsGuessLikeAPI(pageParams)
	// guessList.value = res.result.items
	// 数组追加
	guessList.value.push(...res.result.items)
	// 分页条件
	if (pageParams.page < res.result.pages) {
		// 页码累加
		pageParams.page++
	} else {
		finish.value = true
	}
}
// 重置数据
const resetData = () => {
	pageParams.page = 1
	guessList.value = []
	finish.value = false
}
// 组件挂载完毕
onMounted(() => {
	getHomeGoodsGuessLikeData()
})
// 暴露方法
defineExpose({
	resetData,
	getMore: getHomeGoodsGuessLikeData,
})
</script>

<template>
	<view class="team- flex-cc">
		<view class="head- flex-rbt">
			<view class="head-item">{{ t('myteam.account') }}/{{ t('myteam.nickname') }}</view>
			<view class="head-item">{{ t('myteam.tier') }}</view>
			<view class="head-item">{{ t('myteam.joindate') }}</view>
			<view class="head-item">{{ t('myteam.status') }} </view>
			<view class="head-item">{{ t('myteam.yieldrate') }}</view>
		</view>
		<view class="team-item flex-rbt" v-for="item in guessList" :key="item.id">
			<view class="team-h">类型</view>
			<view class="team-h">状态</view>
			<view class="team-h">状态</view>
			<view class="team-h">状态</view>
			<view class="team-h">状态</view>
		</view>
	</view>
	<view class="loading-text">
		{{ finish ? t('no.more.data') + '~' : t('more.loading') + '...' }}
	</view>
</template>

<style scoped lang="scss">
.team- {
	width: 100%;

	.head- {
		height: 80rpx;
		width: 100%;
		padding: 0 20rpx;
		background-color: #fff;

		.head-item {
			width: 20%;
			text-align: center;
		}
	}

	.team-item {
		width: 100%;
		background-color: #fff;
		margin-bottom: 10rpx;
		padding-top: 8rpx;
		padding-bottom: 8rpx;
		border-bottom: 1rpx solid #cfcfcf;

		.team-h {
			width: 20%;
			padding-top: 6rpx;
			padding-bottom: 6rpx;
			text-align: center;
		}
	}
}

// 加载提示文字
.loading-text {
	text-align: center;
	font-size: 28rpx;
	color: #666;
	padding: 20rpx 0;
}
</style>
